//
//  Storage.m
//  Pods-Storage_Example
//
//  Created by JYHeguang on 2023/11/22.
//

#import "Storage.h"
#import "IStorage.h"

@interface Storage ()
<IStorage>

@property (nonatomic, strong) NSMutableDictionary *storage;
@end

@implementation Storage

- (void)create:(nonnull id)target key:(nonnull id)key { 
    NSAssert(target, @"Storage target is nil");
    NSAssert(key, @"Storage key is nil");
    [self.storage setObject:target forKey:key];
}

- (void)remove:(nonnull id)key {
    NSAssert(key, @"Storage key is nil");
    [self.storage removeObjectForKey:key];
}

- (void)update:(nonnull id)target key:(nonnull id)key {
    NSAssert(target, @"Storage target is nil");
    NSAssert(key, @"Storage key is nil");
    [self.storage setObject:target forKey:key];
}

- (nonnull id)get:(nonnull id)key {
    NSAssert(key, @"Storage key is nil");
    return [self.storage objectForKey:key];
}

- (void)clear {
    [self.storage removeAllObjects];
}

- (NSMutableDictionary *)storage{
    if (!_storage) {
        _storage = @{}.mutableCopy;
    }
    return _storage;
}
@end
